package com.gujiangbo.juc;

import java.util.concurrent.TimeUnit;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/6/10 10:57
 * @Version: 1.0
 * @Description:
 */
public class InterruptDemo3 {

    public static void main(String[] args) {
        //extracted();

        System.out.println(Thread.currentThread().getName() + "\t" + Thread.interrupted());
        System.out.println(Thread.currentThread().getName() + "\t" + Thread.interrupted());
        System.out.println("-------1");
        Thread.currentThread().interrupt();
        System.out.println("-------2");
        System.out.println(Thread.currentThread().getName() + "\t" + Thread.interrupted());
        System.out.println(Thread.currentThread().getName() + "\t" + Thread.interrupted());

    }

    private static void extracted() {
        Thread t1 = new Thread(() -> {
            while (true){
                if (Thread.currentThread().isInterrupted()){
                    System.out.println("当前线程的中断标志位1:" + Thread.interrupted());
                    System.out.println("当前线程的中断标志位2:" + Thread.interrupted());
                    break;
                }
                System.out.println("尚未中断...");
            }

        }, "t1");

        t1.start();
        //暂停5秒钟线程
        try{TimeUnit.MILLISECONDS.sleep(50);} catch (InterruptedException e) {e.printStackTrace();}

        new Thread(()->{t1.interrupt();},"t2").start();
    }
}
